package com.axc.gallery2.edit;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class ToReleaseBitmap {
	BitmapFactory.Options options=new BitmapFactory.Options();
	public Bitmap RelBmp(String filename){
		options.inJustDecodeBounds=true;
		Bitmap bitmap=BitmapFactory.decodeFile(filename,options);
		options.inJustDecodeBounds=false;
		int be=(int)(options.outHeight/(float)480);
		//比屏幕小
		if(be<0)
			be=1;
		options.inSampleSize=be;//保持原始比例
		options.inJustDecodeBounds=false;
		bitmap=BitmapFactory.decodeFile(filename,options); 
		return bitmap;
	}
	public byte[] getImgFromSD(String filename){
		File file=new File(filename);
		int maxBuffere=16*1024;
		@SuppressWarnings("unused")
		int len=0;
		byte[] data=null;
		ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
		BufferedInputStream bufferInputStream;
		try {
			bufferInputStream=new BufferedInputStream(new FileInputStream(file));
			int byteAvailable=bufferInputStream.available();
			int buffereSize=Math.min(byteAvailable, maxBuffere);
			byte[]buffer=new byte[buffereSize];
			while((len=bufferInputStream.read(buffer))!=-1){
				outputStream.write(buffer,0,buffereSize);
			}
			data = outputStream.toByteArray();   
			outputStream.close();   
			bufferInputStream.close(); 

		} catch (Exception e) {
			// TODO: handle exception
		}
		return data;
	}
}
